// 基础响应类型
export interface BaseResponse<T = unknown> {
  code: number
  data: T
  message: string
}

// 用户相关类型
export interface User {
  id: number
  accountName: string
  nickName: string
  email: string
  phoneNumber: string
  userType: UserType
  dormitoryName?: string
  createdAt: string
  updatedAt: string
}

export enum UserType {
  STUDENT = 1,
  REPAIR_WORKER = 2,
  ADMIN = 3,
}

export interface UserLoginRequest {
  accountName: string
  password: string
}

export interface UserRegisterRequest {
  accountName: string
  nickName: string
  password: string
  checkPassword: string
  email: string
  phoneNumber: string
  userType: UserType
  dormitoryName?: string
}

export interface UserUpdateRequest {
  nickName?: string
  email?: string
  phoneNumber?: string
  dormitoryName?: string
}

export interface UserAdminUpdateRequest {
  id: number
  nickName?: string
  email?: string
  phoneNumber?: string
  userType?: UserType
  dormitoryName?: string
}

export interface UserQueryRequest extends BasePageRequest {
  accountName?: string
  nickName?: string
  email?: string
  phoneNumber?: string
  userType?: UserType
}

// 工单相关类型
export interface WorkOrder {
  id: number
  workOrderId: string
  reporterId: number
  handlerId?: number
  categoryId: number
  title: string
  description: string
  location: string
  imagesUrl: string
  status: WorkOrderStatus
  reporterPhoneNumber?: string
  handlerPhoneNumber?: string
  rating?: number
  reviewComment?: string
  createdAt: string
  updatedAt: string
  isDeleted: number
  // 关联信息
  reporterNickName?: string
  reporterAccount?: string
  handlerAccount?: string
  handlerNickName?: string
  categoryName?: string
}

export enum WorkOrderStatus {
  CANCELLED = 0,
  PENDING = 1,
  IN_PROGRESS = 2,
  COMPLETED = 3,
  REVIEWED = 4,
}

// 工单添加请求（与API文档一致）
export interface WorkOrderAddRequest {
  categoryId: number
  title: string
  description?: string
  location: string
  imagesUrl?: string[]
}

// 工单创建请求（用于前端表单）
export interface WorkOrderCreateRequest {
  categoryId?: number
  title: string
  description?: string
  location: string
  contactPhone: string
  images?: string[]
}

export interface WorkOrderUpdateRequest {
  id: number
  categoryId?: number
  title?: string
  description?: string
  location?: string
  imagesUrl?: string[]
  status?: WorkOrderStatus
}

export interface WorkOrderQueryRequest extends BasePageRequest {
  workOrderId?: string
  reporterAccount?: string
  handlerAccount?: string
  categoryId?: number
  categoryName?: string
  title?: string
  location?: string
  status?: WorkOrderStatus
  createdAtStart?: string
  createdAtEnd?: string
  // 保留旧字段以兼容现有代码
  reporterId?: number
  handlerId?: number
}

export interface WorkOrderAssignRequest {
  workOrderId: number
  handlerId: number
}

export interface WorkOrderReviewRequest {
  workOrderId: number
  rating: number
  reviewComment?: string
}

export interface WorkOrderStatsResponse {
  totalCount: number
  pendingCount: number
  completedCount: number
  reviewedCount: number
  cancelledCount: number
  inProgressCount: number
}

// 维修类别类型
export interface RepairCategory {
  id: number
  categoryName: string
  description: string
  isActive: number
  createdAt: string
  updatedAt: string
  isDeleted: number
}

export interface RepairCategoryAddRequest {
  categoryName: string
  description?: string
  isActive?: number
}

export interface RepairCategoryUpdateRequest {
  id: number
  categoryName?: string
  description?: string
  isActive?: number
}

export interface RepairCategoryQueryRequest extends BasePageRequest {
  categoryName?: string
  isActive?: number
}

// 物料类型
export interface Material {
  id: number
  name: string
  model: string
  unit: string
  stockCount: number
  warningThreshold: number
  createdAt: string
  updatedAt: string
  isDeleted: number
}

export interface MaterialAddRequest {
  name: string
  model?: string
  unit: string
  stockCount: number
  warningThreshold: number
}

export interface MaterialUpdateRequest {
  id: number
  name?: string
  model?: string
  unit?: string
  stockCount?: number
  warningThreshold?: number
}

export interface MaterialQueryRequest extends BasePageRequest {
  name?: string
  model?: string
  unit?: string
  isLowStock?: boolean
}

// 通知关联业务类型
export enum NotificationRelatedType {
  WORK_ORDER = 'WORK_ORDER',
  MATERIAL = 'MATERIAL',
  SYSTEM = 'SYSTEM'
}

// 通知类型
export interface Notification {
  id: number
  recipientId: number
  title: string
  content: string
  relatedType: string
  relatedId: number
  isRead: number
  createdAt: string
}

export interface NotificationQueryRequest extends BasePageRequest {
  isRead?: number
  relatedType?: string
}

// 通用类型
export interface UpdateRequest {
  id: number
}

// 菜单类型
export interface MenuItem {
  key: string
  label: string
  icon?: string
  path?: string
  children?: MenuItem[]
  roles?: UserType[]
}

// 技能管理相关类型
export interface MaintenanceSkillAddRequest {
  userId: number
  categoryId: number
}

export interface MaintenanceSkillRemoveRequest {
  userId: number
  categoryId: number
}

export interface MaintenanceSkillQueryRequest extends BasePageRequest {
  userId?: number
  categoryId?: number
  accountName?: string
  nickName?: string
  categoryName?: string
}

export interface MaintenanceSkillResponse {
  userId: number
  accountName: string
  nickName: string
  email: string
  phoneNumber: string
  categoryId: number
  categoryName: string
  categoryDescription: string
  createdAt: string
  updatedAt: string
}

export interface SkillCategoryInfo {
  categoryId: number
  categoryName: string
  categoryDescription: string
  isActive: number
}

export interface UserSkillSummaryResponse {
  userInfo: User
  skills: SkillCategoryInfo[]
}

export interface WorkOrderRecommendRequest {
  workOrderId: number
  count?: number
}

// AI推荐相关类型
export interface AiAssignmentResult {
  success: boolean
  recommendedMaintenanceId?: number
  candidateMaintenanceIds?: number[]
  reason?: string
  confidence?: number
  errorMessage?: string
}

export interface UserResponse {
  id: number
  accountName: string
  nickName: string
  email: string
  phoneNumber: string
  userType: number
  createdAt: string
  updatedAt: string
}

export interface AiRecommendationResponse {
  aiResult: AiAssignmentResult
  recommendedWorkers: UserResponse[]
}

export interface SkillStatsResponse {
  totalMaintenanceWorkers: number
  skilledMaintenanceWorkers: number
  totalSkills: number
  totalSkillAssignments: number
}

// 新的分页响应类型（与API文档一致）
export interface PageResponse<T = unknown> {
  records: T[]              // 数据列表
  current: number           // 当前页码
  size: number             // 每页大小
  total: number            // 总记录数
  pages: number            // 总页数
  hasNext: boolean         // 是否有下一页
  nextCursor: number       // 下一页的游标ID
}

// 分页查询基础类型
export interface BasePageRequest {
  pageSize?: number        // 页面大小
  current?: number         // 当前页码，用于前端分页组件显示
  lastId?: number          // 游标ID，用于游标分页查询（性能优化）
}

// 表格分页类型
export interface PaginationConfig {
  current: number
  pageSize: number
  total: number
  showSizeChanger: boolean
  showQuickJumper: boolean
  showTotal: (total: number, range: [number, number]) => string
}

// 分页状态管理类型（支持双向分页）
export interface PaginationState {
  current: number                    // 当前页码
  pageSize: number                  // 每页大小
  total: number                     // 总记录数
  pages: number                     // 总页数
  hasNext: boolean                  // 是否有下一页
  nextCursor: number                // 下一页游标
  previousPageCursors: number[]     // 前面页面的游标栈，用于支持向后翻页
}
